<template>
	<view class="content">
		<view class="fmt">
			<image src="../../static/img/img/myimg.png" mode="" class="myimg" v-if="!yhInfo.image"></image>
			<image :src="imgUrl+yhInfo.image" mode="" class="myimg cu-avatar" v-if="yhInfo.image"></image>
			<view class="tpcj">
				<view class=" text-sm" @tap="chooseImage">更改封面图</view>
			</view>
		</view>
		<view class="userTop">
			<view class="userInfo">
				<view class="userTop">
					<view class="userImg">
						<view class="imgHy" v-if="token && yhInfo.grade=='普通会员' || yhInfo.grade=='尊贵大会员'">
							<image :src="yhInfo.avatar" mode=""></image>
						</view>
						<image :src="yhInfo.avatar" mode="" v-if="token && yhInfo.grade=='普通用户'"></image>
						<image src="../../static/img/userImg.png" mode="" v-if="!token"></image>
					</view>
					<view class="userLogin" v-if="!token" @click="toLogin">去登录</view>
				</view>
				<view class="userInfoR">
					<p class="name" v-if="yhInfo.userName">{{yhInfo.userName}}</p>
					<p class="name" v-else>{{yhInfo.wechatName}}</p>
					<p>{{yhInfo.grade}}</p>
				</view>
			</view>
		</view>
		<!-- 开通超级会员 -->
		<!-- <view class="ggl">
			<image src="../../static/img/img/hd.png" mode="" class="hdImg"></image>
			<span class="upHy">终身会员</span>
			<span>·免费报名</span>
			<span class="djlq">点击开通></span>
		</view> -->
		<!-- 列表信息 -->
		<view class="listInfo">
			<!-- 活动信息 -->
			<view class="hdInfo">
				<ul>
					<li>
						<p class="text">积分</p>
						<p class="num">{{yhInfo.integral}}</p>
					</li>
					<li>
						<p class="text">活动次数</p>
						<p class="num">{{yhInfo.count}}</p>
					</li>
					<li>
						<p class="text">活动时长（分）</p>
						<p class="num">{{yhInfo.timeCount}}</p>
					</li>
				</ul>
			</view>
			<view class="Info">
				<ul>
					<li @click="toInfo">
						<image src="../../static/img/img/bmxx.png" mode="" class="infoImg"></image>
						<span>报名信息</span>
						<i><image src="../../static/img/img/right.png" mode=""></image></i>
					</li>
					<li @click="toMember">
						<image src="../../static/img/img/wdhy.png" mode="" class="infoImg"></image>
						<span>会员管理</span>
						<i><image src="../../static/img/img/right.png" mode=""></image></i>
					</li>
					<li @click="toActivity">
						<image src="../../static/img/img/tbicon.png" mode="" class="infoImg"></image>
						<span>我的活动</span>
						<i><image src="../../static/img/img/right.png" mode=""></image></i>
					</li>
					<li @click="toOrder">
						<image src="../../static/img/img/ddjl.png" mode="" class="infoImg"></image>
						<span>交易记录</span>
						<i><image src="../../static/img/img/right.png" mode=""></image></i>
					</li>
					<!-- <li @click="toTravels">
						<image src="../../static/img/img/yj.png" mode="" class="infoImg"></image>
						<span>游记管理</span>
						<i><image src="../../static/img/img/right.png" mode=""></image></i>
					</li> -->
					<!-- <li>
						<image src="../../static/img/img/sp.png" mode="" class="infoImg"></image>
						<span>已购商品</span>
						<i><image src="../../static/img/img/right.png" mode=""></image></i>
					</li> -->
					<li @click="toCoupon">
						<image src="../../static/img/img/yhq.png" mode="" class="infoImg"></image>
						<span>优惠券</span>
						<i><image src="../../static/img/img/right.png" mode=""></image></i>
					</li>
					<!-- <li @click="toAbout">
						<image src="../../static/img/img/gy.png" mode="" class="infoImg"></image>
						<span>关于我们</span>
						<i><image src="../../static/img/img/right.png" mode=""></image></i>
					</li> -->
					<li @click="toTf" v-if="status==1">
						<image src="../../static/img/img/gg.png" mode="" class="infoImg"></image>
						<span>广告投放</span>
						<i><image src="../../static/img/img/right.png" mode=""></image></i>
					</li>
					<li @click="toFk">
						<image src="../../static/img/img/fk.png" mode="" class="infoImg"></image>
						<span>我要投诉</span>
						<i><image src="../../static/img/img/right.png" mode=""></image></i>
					</li>
					<!-- <li>
						<image src="../../static/img/img/sz.png" mode="" class="infoImg"></image>
						<span>设置</span>
						<i><image src="../../static/img/img/right.png" mode=""></image></i>
					</li> -->
				</ul>
			</view>
			<button class="tcdl" @click="handleTc" v-if="token">退出登录</button>
		</view>
		<!-- 图片裁剪 -->
		 <view class="contentCc">
			<view class="edgeInsetTop"></view>
			<getCropperImage @ok="getCropperImage" @cancel="oncancle" :url="url" :fixed="false" :blob="false"
				:maxWidth="500" :maxHeight="500" />
		</view>
	</view>
</template>

<script>
	// 引入图片裁剪插件
	import getCropperImage from '@/components/wanl-image-cutter.vue';
	import { userInfo,putInKq,upImage } from '@/api/api.js'
	import config from '@/config'
	export default {
		components: {
            getCropperImage
        },
		data() {
			return {
				imgUrl: config.baseUrl,
				yhInfo:{},
				token:"",
				status:"",
				url: '',
			}
		},
		onLoad() {
			this.getSfkq()
			this.getData()
		  },
		methods: {
			getData(){
				let that = this
				uni.getStorage({
				    key: 'data1',
				    success: function (res) {
						// 查询用户信息表中是否有该手机号
						userInfo(res.data.phone).then((userRes) => {
							that.token = res.data.token
							that.yhInfo = userRes.info
							if(/^data:image\/\w+;base64/.test(that.yhInfo.avatar)){
								that.yhInfo.avatar =  that.yhInfo.avatar
							}else if(that.yhInfo.avatar=='undefined'||!that.yhInfo.avatar){
								that.yhInfo.avatar =  that.imgUrl+'/default/USER_DEFAULT_AVATAR_URL.png'
							}else{
								that.yhInfo.avatar =  that.imgUrl+that.yhInfo.avatar
							}
						  })
				    }
				});
			},
			
			// 去登录按钮
			toLogin(){
				uni.navigateTo({
					url: '../login/login',
				});
			},
			// 广告是否开启
			getSfkq(){
				putInKq().then((res) => {
					if(res.data.length>0){
						this.status = res.data[0].switch
					}
				  })
			},
			// 跳转报名信息
			toInfo(id) {
				if(this.token){
					uni.navigateTo({
						url: '../user/info',
					});
				}else{
					uni.navigateTo({
						url: '../login/login',
					});
				}
			},
			// 跳转会员管理
			toMember(id) {
				if(this.token){
					uni.navigateTo({
						url: '../user/member',
					});
				}else{
					uni.navigateTo({
						url: '../login/login',
					});
				}
			},
			
			// 我的活动跳转
			toActivity(id) {
				if(this.token){
					uni.navigateTo({
						url: '../user/activity',
					});
				}else{
					uni.navigateTo({
						url: '../login/login',
					});
				}
			},
			
			// 跳转订单页面
			toOrder(id) {
				if(this.token){
					uni.navigateTo({
						url: '../user/order',
					});
				}else{
					uni.navigateTo({
						url: '../login/login',
					});
				}
			},
			// 跳转游记管理
			toTravels(id) {
				if(this.token){
					uni.navigateTo({
						url: '../user/travels',
					});
				}else{
					uni.navigateTo({
						url: '../login/login',
					});
				}
			},
			
			// 优惠券
			toCoupon(id) {
				if(this.token){
					uni.navigateTo({
						url: '../user/coupon',
					});
				}else{
					uni.navigateTo({
						url: '../login/login',
					});
				}
			},
			
			// 关于我们
			toAbout(){
				uni.navigateTo({
					url: '../user/about',
				});
			},
			// 我要反馈
			toFk(){
				if(this.token){
					uni.navigateTo({
						url: '../user/feedback',
					});
				}else{
					uni.navigateTo({
						url: '../login/login',
					});
				}
			},
			// 广告投放
			toTf(){
				if(this.token){
					uni.navigateTo({
						url: '../user/putIn',
					});
				}else{
					uni.navigateTo({
						url: '../login/login',
					});
				}
			},
			// 点击选择图片
			chooseImage() {
				uni.chooseImage({
					count: 1, // 默认9
					sizeType: ['compressed'], // 可以指定是原图还是压缩图，默认二者都有
					sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机，默认二者都有
					success: res => {
						console.log('11111111111111',res)
						// 设置url的值，显示控件
						this.url = res.tempFilePaths[0];
					}
				});
			},
			// 上传图片
			getCropperImage(e) {
				// 这里走接口替换的值
				this.yhInfo.image = e.path;
				this.url = '';
				// 上传图片至服务器
				uni.uploadFile({					  url: this.imgUrl+'/index.php/api/banner/upload', // 你的ThinkPHP服务器地址					  filePath: e.path,					  name: 'file',					  success: uploadFileRes => {						// 处理返回的图片路径						let data = JSON.parse(uploadFileRes.data);						if (data.code === 200) {
						  // 修改封面数据库图片
						  let imgData = {
						  	image:data.filename,
						  	phone:this.yhInfo.phone
						  }
						  upImage(imgData).then((res) => {
						  	this.getData()
						    })						} else {						  // 图片上传失败						  console.log('图片上传失败：' + data.msg);						}					  },					  fail: uploadFileError => {						// 上传失败的处理						console.error('上传失败：', uploadFileError);					  }					});
			},
			// 点击返回清空组件值
			oncancle() {
				this.url = '';
			},
			// 退出登录
			handleTc(){
				uni.showModal({
					title: '提示：',
					content: '是否要退出登录？',
					success: function(res) {
						if (res.confirm) {
						   uni.clearStorageSync();
							setTimeout(function() {
								uni.reLaunch({
								  url: '/pages/index/index'
								});
							}, 500);
							
						} else if (res.cancel) {
							// console.log('取消');
							//TODO
							return
						}
					}
			});
			}
		}
	}
</script>

<style>
	
	.content{
		/* background-color: #fff; */
	}
	.userTop{
		/* background: linear-gradient(to bottom, #6a8473,#8dbc90);
		height: 120px; */
		display: flex;
		position: absolute;
		top: 30rpx;
	}
	.userInfo{
		display: flex;
		padding: 10px;
	}
	
	.userInfo image{
		width: 120rpx;
		height: 120rpx;
		border-radius: 100rpx;
		border: 1px solid #fff;
	}
	.userInfoR{
		padding-left: 10px;
		font-size: 14px;
		margin-top: 20rpx;
		line-height: 25px;
		color: #fff;
		margin-left: 133rpx;
	}
	
	.name{
		font-weight: bold;
	}
	
	.ggl{
		height: 45px;
		line-height: 45px;
		background: linear-gradient(to right, #8dbc90, #5b895e);
		color: #4f6851;
		font-size: 12px;
		padding: 0 10px;
		border-radius: 5px;
		margin-bottom: 10px;
		box-shadow: 1px 1px 10px #c1c1c1;
		margin:10px 0;
	}
	
	.hdImg{
		width: 22px;
		height: 18px;
		position: relative;
		top: 3px;
		margin-right: 5px;
	}
	
	.upHy{
		font-weight: 600;
		font-size: 13px;
	}
	
	.djlq{
		float: right;
	}
	
	/* .hdInfo{
		padding: 0 10px;
	} */
	
	.hdInfo ul{
		display: flex;
		/* background-color: #fff;
		border-radius: 5px; */
	}
	
	.hdInfo ul li{
		margin: 0 10px;
		/* border-radius: 5px; */
		width: 33%;
		text-align: center;
		padding: 10px 0;
	}
	
	.text{
		font-size: 12px;
		margin-top: 5px;
		color: #b9b9b9;
	}
	
	.Info ul li{
		display: flex;
		padding: 5px 0;
		border-bottom: 1px dotted #e6e6e6;
		margin-top: 10px;
	}
	
	.listInfo ul li span{
		width: 98%;
		font-size: 14px;
		color: #b9b9b9;
	}
	
	.listInfo ul li image{
		width: 15px;
		height: 15px;
	}
	
	.listInfo{
		border-radius: 5px;
		background-color: #fff;
		border-top-left-radius: 20px;
		border-top-right-radius: 20px;
		width: 90%;
		margin: -48rpx auto 0;
		padding: 10px;
		z-index: 1;
		position: relative;
		box-shadow: 1px 1px 10rpx #ddd;
	}
	
	.infoImg{
		width: 30px;
		margin-top: 2px;
		margin-right: 5px;
	}
	
	.tcdl{
		background: #6a8473;
		color: #fff;
		font-size: 15px;
		border: 1px solid #6a8473;
		width:95%;
		margin: 20px auto 0;
	}
	
	.userLogin{
		color: #fff;
		margin-top: 35rpx;
		font-size: 30rpx;
		color: #fff;
		margin-left: 20rpx;
		width: 150rpx;
	}
	
	.myimg{
		width: 100%;
		height: 100%
	}
	
	.imgHy{
		width: 120rpx;
		height: 120rpx;
		background-image: url('../../static/img/img/hy.png');
		background-repeat: no-repeat;
		background-size: 100% 100%;
		position: relative;
	}
	
	
	.imgHy image{
		width: 100%;
		height: 100%;
		position: absolute;
		bottom: -42rpx;
		left: 0;
		right: 0;
		margin: 0 auto;
	}
	
	.fmt{
		width: 100%;
		height: 369rpx;
		position: relative;
	}
	
	.tapImg{
		border: 1px solid red;
		position: absolute;
		top: 0;
		right: 0;
	}
	
	.tpcj{
		position: absolute;
		right: 10rpx;
		top: 10rpx;
		background-color: rgba(255,255,255,0.2);
		padding: 5rpx 10rpx;
		border-radius: 10rpx;
		font-size: 24rpx;
		/* color: #698376; */
		color: #fff;
	}
	
	.contentCc {
			display: flex;
			justify-content: center;
			align-items: center;
		}
	
		.avatar {
			width: 180rpx;
			height: 180rpx;
			margin: 20rpx auto;
			background-color: #e5e5e5;
			border-radius: 50%;
			background-position: center;
			background-size: 100%;
		}
</style>
